// 数字变化动画
export function animateNumber(
  element: HTMLElement, 
  start: number, 
  end: number, 
  duration: number = 500
) {
  const startTime = performance.now()
  const change = end - start

  function update(currentTime: number) {
    const elapsed = currentTime - startTime
    const progress = Math.min(elapsed / duration, 1)
    
    // 使用缓动函数使动画更自然
    const easeProgress = easeOutQuart(progress)
    const current = start + change * easeProgress
    
    element.textContent = Math.round(current).toString()

    if (progress < 1) {
      requestAnimationFrame(update)
    }
  }

  requestAnimationFrame(update)
}

// 缓动函数
function easeOutQuart(x: number): number {
  return 1 - Math.pow(1 - x, 4)
}

// 震动效果
export function shake(element: HTMLElement) {
  element.classList.add('shake')
  element.addEventListener('animationend', () => {
    element.classList.remove('shake')
  }, { once: true })
} 